using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using AspNetForums;
using AspNetForums.Controls;
using AspNetForums.Components;

namespace AspNetForums.Admin 
{
	/// <summary>
	/// Summary description for ManageForums.
	/// </summary>
	public class ManageForums : System.Web.UI.Page {
		protected System.Web.UI.WebControls.Repeater forumGroupRepeater;

		private void Page_Load(object sender, System.EventArgs e)
		{

			// Put user code to initialize the page here
				DataBindForumGroups();
		}
    
		// *******************************************************************
		// DataBindForumGroups
		//
		/// <summary>
		/// Databinds the forum group repeater
		/// </summary>
		//
		// ********************************************************************
		public void DataBindForumGroups() {

			forumGroupRepeater.DataSource = ForumGroups.GetForumGroups(false, true);
			forumGroupRepeater.DataBind();

		}

		// *******************************************************************
		// MoveForumGroupDown_Click
		//
		/// <summary>
		/// Used to control moving Forum Groups up and down in the sort order
		/// </summary>
		//
		// ********************************************************************
		public void btnMoveForumGroupDown_Click(Object sender, ImageClickEventArgs e) {

			int selectedForumGroup = Convert.ToInt32( ((ImageButton) sender).CommandArgument);

			ForumGroups.ChangeForumGroupSortOrder(selectedForumGroup, false);

			DataBindForumGroups();

		}

		// *******************************************************************
		// MoveForumGroupUp_Click
		//
		/// <summary>
		/// Used to control moving Forum Groups up and down in the sort order
		/// </summary>
		//
		// ********************************************************************
		public void btnMoveForumGroupUp_Click(Object sender, ImageClickEventArgs e) {
        
			int selectedForumGroup = Convert.ToInt32( ((ImageButton) sender).CommandArgument);

			ForumGroups.ChangeForumGroupSortOrder(selectedForumGroup, true);

			DataBindForumGroups();

		}
    
    
		// *******************************************************************
		// MoveForumDown_Click
		//
		/// <summary>
		/// Used to control moving Forum Groups up and down in the sort order
		/// </summary>
		//
		// ********************************************************************
		public void btnMoveForumDown_Click(Object sender, ImageClickEventArgs e) {

			int selectedForum = Convert.ToInt32( ((ImageButton) sender).CommandArgument);

			Forums.ChangeForumSortOrder(selectedForum, false);

			DataBindForumGroups();

		}

		// *******************************************************************
		// MoveForumUp_Click
		//
		/// <summary>
		/// Used to control moving Forum Groups up and down in the sort order
		/// </summary>
		//
		// ********************************************************************
		public void btnMoveForumUp_Click(Object sender, ImageClickEventArgs e) {
        
			int selectedForum = Convert.ToInt32( ((ImageButton) sender).CommandArgument);

			Forums.ChangeForumSortOrder(selectedForum, true);

			DataBindForumGroups();

		}    

		// *******************************************************************
		// CreateNewForum_Click
		//
		/// <summary>
		/// Used to create a new forum
		/// </summary>
		//
		// ********************************************************************
		public void btnCreateNewForum_Click(Object sender, EventArgs e) {

			Button b = (Button) sender;
			TextBox t = (TextBox) b.Parent.FindControl("ForumName");

			// Create the forum
			//
			Forum forum = new Forum();
			forum.ForumGroupID = int.Parse(b.CommandArgument);
			forum.Name = t.Text;

			int forumID = Forums.AddForum(forum);

			DataBindForumGroups();

		}
    
    
		// *******************************************************************
		// CreateNewForumGroup_Click
		//
		/// <summary>
		/// Used to create a new forum group
		/// </summary>
		//
		// ********************************************************************
		public void btnCreateNewForumGroup_Click(Object sender, EventArgs e) {

			Button b = (Button) sender;
			TextBox t = (TextBox) b.Parent.FindControl("ForumGropName");

			// Create the forum group
			//
			ForumGroup group = new ForumGroup(t.Text);
			ForumGroups.AddForumGroup(group);

			DataBindForumGroups();

		}
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e) {
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() {    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

	}
}

/*

<script runat="server">
 
    // ****************************************************************
    // Page_Load 
    //
    /// <summary>
    /// Event used to set the initial state of the page.
    /// </summary>
    // ****************************************************************
    public void Page_Load (Object sender, EventArgs e) {

       // Bind the data
       //
       DataBindForumGroups();
       
    }
    
    // *******************************************************************
    // DataBindForumGroups
    //
    /// <summary>
    /// Databinds the forum group repeater
    /// </summary>
    //
    // ********************************************************************
public void DataBindForumGroups() {

forumGroupRepeater.DataSource = ForumGroups.GetForumGroups(false, true);
forumGroupRepeater.DataBind();

}
    

    
</script>
*/